import React from 'react';
import * as asyncLoad from '../util/asyncLoad';
import { workflowPublicFiles } from '../constants/fileConfig';
import {observer,inject} from "mobx-react/index";
@observer
export default class TagTypeSelect extends React.Component{
    constructor(){
        super();
        this.state = {hasLoad: false,store: null};
    }
    componentDidMount(){
        const init = () =>{
            const { FollowTypeSettingStore } = window.weaWorkflowPublic;
            const store = new FollowTypeSettingStore();
            this.setState({hasLoad: true,store:store});
            window.followTypeSettingStore = store//抛出store给unitll用
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, init);
        this.timerID=setTimeout(()=>{ 
            $(".wf_attention_div_btn").on("mouseover mouseout",function(event){
                const str = $(this).attr('id').substr($(this).attr('id').indexOf('_'))
                if(event.type == "mouseover"){  
                 jQuery("#attentionSpan"+str).css("display","inline-block")
                }else if(event.type == "mouseout"){
                 jQuery("#attentionSpan"+str).css("display","none")
                }
               })
         },1000)
    }
    componentDidUpdate(){
        this.timerID=setTimeout(()=>{ 
            $(".wf_attention_div_btn").on("mouseover mouseout",function(event){
                const str = $(this).attr('id').substr($(this).attr('id').indexOf('_'))
                if(event.type == "mouseover"){  
                 jQuery("#attentionSpan"+str).css("display","inline-block")
                }else if(event.type == "mouseout"){
                 jQuery("#attentionSpan"+str).css("display","none")
                }
               })
         },1000)
      }
    componentWillUnmount() {
        clearTimeout(this.timerID);
    }
    addBtnClick=(value)=>{
        const { hasLoad ,store} = this.state;
        const {saveAttentionTypeSet,getAttentionTypeSet} = store
        const {curStore} = this.props;
        saveAttentionTypeSet({showname:value,src:'saveData2',id:curStore.FollowRequestid})
    }
    onVisibleChange=(v)=>{
        const {curStore} = this.props;
        curStore.followTypeSelectShow = false
    }
    followMakeSure=()=>{//点击确定之后刷新列表
        const {curStore} = this.props;
        const { location,refresh } = this.props;
        const urlParams = location.query || {};
        refresh();
        curStore.followTypeSelectShow = false
    }
    render(){
        const { hasLoad ,store} = this.state;
        const {curStore,commonParam} = this.props
        if(hasLoad){
            const {TagTypeSelect} = window.weaWorkflowPublic;
            return (
                <TagTypeSelect ecId={`${this && this.props && this.props.ecId || ''}_TagTypeSelect@btuws9`} 
                followTypeSettingStore={store}
                button={''} //自定义dom
                FollowRequestid={commonParam.requestid||""}
                visible={curStore.followTypeSelectShow} 
                onVisibleChange={this.onVisibleChange} 
                addBtn={this.addBtnClick}
                placement={'bottom'}
                makeSureCallBack={()=>{this.followMakeSure()}}
                />);
        }else{
            return ( <div></div>);
        }
    }
}

